package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.SoftwareQueryDto;
import com.group.eams.pojo.entity.Software;
import com.group.eams.pojo.vo.SoftwareAccountVo;
import com.group.eams.pojo.vo.SoftwareAuthorizationVo;
import com.group.eams.pojo.vo.SoftwareListVo;
import com.group.eams.service.SoftwareService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 无形资产(软件)表(Software)表控制层
 *
 * @author DHUser
 * @since 2024-10-30 12:58:29
 */
@RestController
@RequestMapping("/software")
public class SoftwareController  {
    /**
     * 服务对象
     */
    @Autowired
    private SoftwareService softwareService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public Result findById(@RequestParam Long id) {
        Software software = softwareService.findById(id);
        return Result.buildSuccess(software);
    }

    /**
     * 分页查询所有数据
     *
     * @param softwareQueryDto 查询实体
     * @return 所有数据
     */

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(SoftwareQueryDto softwareQueryDto) {
        Page<SoftwareListVo> page = softwareService.findByQueryDto(softwareQueryDto);
        return Result.buildSuccess(page.getTotal(),page.getRecords());
    }

    /**
     * 查询所有数据
     * @return
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll() {
        List<Software> list = softwareService.findAll();
        return Result.buildSuccess(list);
    }

    /**
     * 查询基本信息
     * @return
     */
    @RequestMapping(value = "/findBasicById",method = RequestMethod.GET)
    public Result findBasicById(@RequestParam Long id) {
        SoftwareListVo softwareListVo = softwareService.findBasicById(id);
        return Result.buildSuccess(softwareListVo);
    }
    /**
     * 查询授权信息
     * @return
     */
    @RequestMapping(value = "/findAuthorizationById",method = RequestMethod.GET)
    public Result findAuthorizationById(@RequestParam Long id) {
       SoftwareAuthorizationVo softwareAuthorizationVo = softwareService.findAuthorizationById(id);
       return Result.buildSuccess(softwareAuthorizationVo);
    }

    /**
     * 查询财务信息
     * @return
     */
    @RequestMapping(value = "/findAccountById",method = RequestMethod.GET)
    public Result findAccountById(@RequestParam Long id) {
        SoftwareAccountVo  softwareAccountVo = softwareService.findAccountById(id);
        return Result.buildSuccess(softwareAccountVo);
    }

    /**
     * 新增数据
     *
     * @param software 实体对象
     * @return 新增结果
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody Software software) {
        boolean result = softwareService.save(software);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量新增数据
     *
     * @param softwareList 实体对象
     * @return 新增结果
     */
    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    public Result addBatch(@RequestBody List<Software> softwareList) {
        boolean result = softwareService.saveBatch(softwareList);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改数据
     *
     * @param software 实体对象
     * @return 修改结果
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody Software software) {
        boolean result = softwareService.updateById(software);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改数据
     *
     * @param softwareList 实体对象
     * @return 修改结果
     */
    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    public Result updateBatch(@RequestBody List<Software> softwareList) {
        boolean result = softwareService.updateBatchById(softwareList);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(@RequestParam Long id) {
        boolean result = softwareService.removeById(id);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量删除数据
     *
     * @param batchDeleteDto 批量删除实体对象
     * @return 删除结果
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    public Result deleteBatch(@RequestBody BatchDeleteDto batchDeleteDto) {
        boolean result = softwareService.removeByIds(batchDeleteDto.getIds());
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

}

